package com.itheima.mapper;

import com.itheima.pojo.Dept;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface DeptMapper {
    /**
     * 查询所有部门
     */
//    @Select("select * from dept")
    public List<Dept> findAll();

    //根据id删除部门
    @Delete("delete from dept where id = #{id}")
    public void deleteById(@Param("id") Integer id);

    //添加部门
    @Insert( "insert into dept(name,create_time,update_time) values(#{name},#{createTime},#{updateTime})" )
    public void save(Dept dept);

    //根据id查询部门
    @Select("select * from dept where id = #{id}")
    public Dept getById(@Param("id") Integer id);
    /**
     * 更新部门
     */
    @Update("update dept set name = #{name},update_time = #{updateTime} where id = #{id}")
    void update(Dept dept);

    //查询该部门的员工数量
    @Select("select count(id) from emp where dept_id = #{id}")
    Integer countByDeptId(Integer id);
}